﻿using System;
using System.Windows;
using Kiva7.DataRequests;
using Kiva7.Settings;
using Microsoft.Phone.Tasks;

namespace Kiva7.Pages
{
    public partial class AboutPage
    {
        private const string Url = "/Pages/AboutPage.xaml";
        public static readonly Uri PageUrl = new Uri(Url, UriKind.RelativeOrAbsolute);
        private StatisticsRssRequest _request;

        public AboutPage()
        {
            InitializeComponent();
            CreateStandardControls();
        }

        private void SendSupportClick(object sender, RoutedEventArgs e)
        {
            var email = new EmailComposeTask
                            {
                                To = "Kiva7@live.com",
                                Body =
                                    "Support question from Windows Phone from: " +
                                    AppSettings.Current.LenderIdSetting
                            };
            email.Show();
        }

        private void OpenKivaClick(object sender, RoutedEventArgs e)
        {
            var task = new WebBrowserTask
                {
                    Uri = new Uri("http://www.kiva.org")
                           };
            task.Show();
        }

        private void OpenAvanadeClick(object sender, RoutedEventArgs e)
        {
            var task = new WebBrowserTask
                           {
                               Uri = new Uri( "http://www.avanade.com")
                           };
            task.Show();
        }

        private void PhoneApplicationPageLoaded(object sender, RoutedEventArgs e)
        {
            if (_request == null)
            {
                _request = new StatisticsRssRequest();
                lbxStatistics.ItemsSource = _request.Data;
                _request.GetStatistics();
            }
        }
    }
}